package com.briup.srms.sms.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.srms.sms.bean.DormitoryType;
import com.briup.srms.sms.bean.extend.DormitoryTypeExtend;
import com.briup.srms.sms.service.IDormitoryTypeService;
import com.jacky.base.utils.Message;
import com.jacky.base.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @program: 杰普基础管理系统
 * @description: 宿舍类型控制器类
 * @author: charles
 * @create: 2020-12-27 17:22
 **/
@Api(description = "宿舍类型相关接口")
@Validated
@RestController
@RequestMapping("/dormitoryType")
public class DormitoryTypeController {

	@Autowired
	private IDormitoryTypeService dormitoryTypeService;
	
	
	@ApiOperation(value = "查询所有宿舍类型信息")
	@GetMapping("findAll")
	public Message findAll() {
		List<DormitoryType>  list = dormitoryTypeService.findAll();
		return MessageUtil.success(list);
	}
	

	@ApiOperation(value = "通过ID查询宿舍类型携带照片信息")
	@GetMapping("findById")
	public Message findById(long id) {
		DormitoryTypeExtend type = dormitoryTypeService.findById(id);
		return MessageUtil.success(type);
	}
	
	@ApiOperation(value = "查询所有宿舍类型携带照片信息")
	@GetMapping("findAllWithPhoto")
	public Message findAllWithPhoto() {
		List<DormitoryTypeExtend>  list = dormitoryTypeService.findAllWidthPhoto();
		return MessageUtil.success(list);
	}

	@ApiOperation(value = "通过id删除")
	@ApiImplicitParams(@ApiImplicitParam(name = "id", value = "主键", paramType = "query", required = true))
	@GetMapping("deleteById")
	public Message deleteById(long id) {
		dormitoryTypeService.deleteById(id);
		return MessageUtil.success("删除成功");
	}

	@ApiOperation(value = "保存或更新消息信息", notes = "如果参数中包含id后端认为是更新操作，如果参数中不包含id认为是插入操作")
	@PostMapping("saveOrUpdate")
	public Message saveOrUpdate(DormitoryType dormitoryType) {
		dormitoryTypeService.saveOrUpdate(dormitoryType);
		return MessageUtil.success("更新成功");
	}
}
